<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\BaseController;
use app\middleware\admin\Auth;
use app\model\Annunciate;

class Annunciates extends BaseController
{
    protected $middleware=[Auth::class];

    public function index($limit=10)
    {
        $name = request()->param('name');
        $status = request()->param('status');
        $time = request()->param('time');
        $data= Annunciate::with(['admin'])->when($name, function ($query) use ($name) {
            $query->whereRaw('(concat(content,name) like "%' . $name . '%")');
        })->when($status, function ($query) use ($status) {
            $query->where('status', $status);
        })->when($time, function ($query) use ($time) {
            $query->whereBetween('create_time', $time);
        })->order('id','desc')->paginate($limit);
        return $this->success($data);
    }

    public function create()
    {
        $params = request()->param();
        $params['admins_id'] = request()->userid;
        Annunciate::create($params);
        return $this->success();
    }

    public function update($id)
    {
        Annunciate::where('id',$id)->update(request()->param());
        return $this->success();
    }

    public function delete($id)
    {
        Annunciate::where('id','in',$id)->delete();
        return $this->success();
    }


}
